package demo1;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {



    //最大连续1的个数
    //11100011110
    public int longestOnes(int[] nums, int k) {
        int sz = nums.length-1;
        int count = 0;
        int len = Integer.MIN_VALUE;
        int left = 0;
        int right = 0;

        while(right<=sz){
            while (count <= k) {
                if (nums[right] == 0) {
                    count++;
                }
                right++;
            }
            len = Math.max(len,right-left);
            while (count == k) {
                if (nums[left] == 0) {
                    count--;
                }
                left++;
            }
        }
        return len;
    }

    //最小元素和最大元素的最小平均值
    public double minimumAverage(int[] nums) {
        int right = nums.length-1;
        int left = 0;
        double ret = 100000;
        Arrays.sort(nums);
        while(left<right){
            ret = Math.min(ret,(double)nums[left]+nums[right]/2);
        }
        return ret;
    }
}
